from settings import Setting

# index
from application.index.controller.index import index_index
from application.index.controller.upload import index_upload
from application.index.controller.article import index_article
from application.index.controller.link import index_link
from application.index.controller.timeline import index_timeline
# admin
from application.admin.controller.index import admin_index
from application.admin.controller.welcome import admin_welcome
from application.admin.controller.login import admin_login
from application.admin.controller.article import admin_article
from application.admin.controller.user import admin_user
from application.admin.controller.menu import admin_menu
from application.admin.controller.error import admin_error
from application.admin.controller.icons import admin_icons
from application.admin.controller.web_config import admin_web_config

# api
from application.api.controller.index import api_index
from application.api.controller.upload import api_upload
from application.api.controller.menu import api_menu
from application.api.controller.article import api_article

def init_register_blue_point(app):
    # index蓝图
    app.register_blueprint(index_index, url_prefix=index_index.url_prefix)
    app.register_blueprint(index_article, url_prefix=index_article.url_prefix)
    app.register_blueprint(index_link, url_prefix=index_link.url_prefix)
    app.register_blueprint(index_timeline, url_prefix=index_timeline.url_prefix)
    app.register_blueprint(index_upload, url_prefix=index_upload.url_prefix)
    # admin蓝图
    app.register_blueprint(admin_index, url_prefix=admin_index.url_prefix)
    app.register_blueprint(admin_login, url_prefix=admin_login.url_prefix)
    app.register_blueprint(admin_welcome, url_prefix=admin_welcome.url_prefix)
    app.register_blueprint(admin_user, url_prefix=admin_user.url_prefix)
    app.register_blueprint(admin_article, url_prefix=admin_article.url_prefix)
    app.register_blueprint(admin_menu, url_prefix=admin_menu.url_prefix)
    app.register_blueprint(admin_error, url_prefix=admin_error.url_prefix)
    app.register_blueprint(admin_icons, url_prefix=admin_icons.url_prefix)
    app.register_blueprint(admin_web_config, url_prefix=admin_web_config.url_prefix)

    # api蓝图
    app.register_blueprint(api_index, url_prefix=api_index.url_prefix)
    app.register_blueprint(api_upload, url_prefix=api_upload.url_prefix)
    app.register_blueprint(api_menu, url_prefix=api_menu.url_prefix)
    app.register_blueprint(api_article, url_prefix=api_article.url_prefix)


# UPLOAD_FOLDER = '/path/to/the/uploads'
# ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}


def init_website_app_config(app):
    pass
    # path = "{}/app.yaml".format(app.root_path)
    # app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
    # app_yaml = read_yaml_file(path)
    # db_user = app_yaml['website']['database']['username']
    # db_pass = app_yaml['website']['database']['password']
    # db_name = app_yaml['website']['database']['dbname']
    # db_url = app_yaml['website']['database']['url']
    # db_port = app_yaml['website']['database']['port']
    # db_uri = "mysql+pymysql://{}:{}@{}:{}/{}".format(db_user, db_pass, db_url, db_port, db_name)
    # print(db_uri)
    # app.config["SQLALCHEMY_DATABASE_URI"] = db_uri
    # app.config["SQLALCHEMY_POOL_RECYCLE "] = 10
    # app.config["SQLALCHEMY_POOL_SIZE  "] = 30
    # app.config["SQLALCHEMY_POOL_TIMEOUT  "] = 3
    # app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True


    # Setting.style = get_website_style(app)
    # Setting.app_path = app.root_path
    # Setting.token = get_server_token(app)
    # Setting.branch = get_deploy_branch(app)
    # Setting.secret = get_server_secret(app)
    # Setting.upload_path = get_server_upload(app)
    # Setting.oss_access_secret = get_oss_access_secret(app)
    # Setting.oss_end_point = get_oss_end_point(app)
    # Setting.oss_access_key = get_oss_access_key(app)
    # Setting.oss_bucket_name = get_oss_bucket_name(app)
    # Setting.email = get_email(app)
    # Setting.auth_code = get_auth_code(app)
    # Setting.qq_appId = get_qq_app_id(app)
    # Setting.qq_appKey = get_qq_app_key(app)
    # Setting.qq_callBack = get_qq_callback(app)
    # Setting.qq_url = get_qq_url(app)
    # Setting.qq_token_expires = get_qq_token_expires(app)
